package com.sunny.ynhz.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StyleRes;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.sunny.ynhz.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by luao on 2017/6/26.
 */

public class RiverSelectDialog extends Dialog {
    @BindView(R.id.rivers_selected_recycle)
    RecyclerView rivers_selected_recycle;
    @BindView(R.id.cancel)
    TextView cancel;
    @BindView(R.id.confirm)
    TextView confirm;
    @BindView(R.id.titleText)
    TextView titleText;

    private String title;
    private RiverSelectDialog diaLog;

    public interface onClickCancelButtonListener {
        public void onCancelClick();
    }

    public interface onClickComfirmButtonListener {
        public void onComfirmClick();
    }

    public static RiverSelectDialog builder(Context context) {
        return new RiverSelectDialog(context, R.style.AddProblemTypeDialog);
    }


    private onClickCancelButtonListener onClickCancelButtonListener;
    private onClickComfirmButtonListener onClickComfirmButtonListener;

    public RiverSelectDialog onClickCancelButton(onClickCancelButtonListener onClickCancelButtonListener) {
        this.onClickCancelButtonListener = onClickCancelButtonListener;
        return this;
    }

    public RiverSelectDialog onClickComfirmButton(onClickComfirmButtonListener onClickComfirmButtonListener) {
        this.onClickComfirmButtonListener = onClickComfirmButtonListener;
        return this;
    }

    public RiverSelectDialog(@NonNull Context context) {
        super(context);
    }

    public RiverSelectDialog(@NonNull Context context, @StyleRes int themeResId) {
        super(context, themeResId);
    }

    protected RiverSelectDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_select_river);
        ButterKnife.bind(this);
        setCanceledOnTouchOutside(false);

        diaLog = this;

        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onClickCancelButtonListener.onCancelClick();
                diaLog.dismiss();
            }
        });
        titleText.setText(title);
        confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onClickComfirmButtonListener.onComfirmClick();
            }
        });
    }

    //不能直接调用控件，这个时候还没有调用oncreat;控件还没绑定
    public RiverSelectDialog setTitleText(String title) {
        this.title = title;
        return this;
    }


}
